package cc.gpai.util.slotboard;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

public abstract class AbstractSignal<E> implements Signal<E> {

	protected List<Method> methods = new ArrayList<Method>();
	private String name;

	public AbstractSignal() {
		this(String.valueOf(SlotBoard.rand.nextLong()));
	}

	public AbstractSignal(String name) {
		this.name = name;
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		if (methods.contains(method)) {
			return SlotBoard.deliverSignal(new SignalEvent(this, method, args));
		} else {
			return method.invoke(this, args);
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}
